package ocr

import (
	"github.com/duke-git/lancet/v2/slice"
	"github.com/gin-gonic/gin"
)

// 一些基础的接口还有其他

// 基础的路由接口
type IRouteBaseCompose interface {
	Group(path string) IRouteGroup
	Use(handles ...OcrHandler)
	GET(path string, handlers ...OcrMiddle)
	POST(path string, handlers ...OcrMiddle)
	PUT(path string, handlers ...OcrMiddle)
	DELETE(path string, handlers ...OcrMiddle)
}

type IRequest func(path string, handlers ...OcrMiddle)

// ocr中间件构型
type IHandle interface {
	createOcrHandle() gin.HandlerFunc
}
type OcrMiddle func(c *gin.Context)

// 可以控制哪些路径不需要走该中间件
type OcrHandler struct {
	Exclude []string  //需要忽略的fullPath
	Handler OcrMiddle //中间件
}

// 装饰每个中间件
func (o OcrHandler) createOcrHandle(basePath string) gin.HandlerFunc {
	for i := 0; i < len(o.Exclude); i++ {
		o.Exclude[i] = basePath + o.Exclude[i]
	}
	return func(c *gin.Context) {
		if slice.Contain(o.Exclude, c.FullPath()) {
			c.Next()
			return
		}
		o.Handler(c)
	}
}
